import torch


def extract_sepctrum_from_cnhw_Tensor(cnhw, ROI_h, ROI_w, ROI_size):
    spectrum = cnhw[0, :, ROI_h - ROI_size // 2:ROI_h + ROI_size // 2, ROI_w - ROI_size // 2:ROI_w + ROI_size // 2]
    spectrum = torch.mean(spectrum, dim=[1, 2])
    spectrum = spectrum.cpu().detach().numpy()
    return spectrum
